package com.alan.wifishare.view.impl.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.alan.libapi.model.business.UserToken;
import com.alan.libapi.model.persistent.ModifyPwdType;
import com.alan.library.allog.KLog;
import com.alan.wifishare.R;
import com.alan.wifishare.presenter.UserModifyPwdPS;
import com.alan.wifishare.view.BaseActivity;
import com.alan.wifishare.view.impl.ActivityJumpUtil;
import com.alan.wifishare.view.iview.IVUserModifyPwd;

/**
 * @className: UserModifyPwdActivity
 * @describtion: UserModifyPwdActivity
 * @author: AlanWang
 * @email: 850267876@qq.com
 * @time: 2016/5/5 20:04
 */
public class UserModifyPwdActivity extends BaseActivity implements IVUserModifyPwd, View.OnClickListener {

    private UserModifyPwdPS userModifyPwdPS;
    private Button userModifyPwdBackBtn;
    private EditText userModifyPwdNewPwdEt;
    private EditText userModifyPwdConfirmPwdEt;
    private Button userModifyPwdSubmitBtn;
    private ModifyPwdType modifyPwdType;
    private UserToken userToken;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_modify_pwd_layout);
        initView();
        userModifyPwdPS = new UserModifyPwdPS(this);
    }

    @Override
    protected void initView() {
        userModifyPwdBackBtn = (Button)findViewById(R.id.userModifyPwdBackBtn);
        userModifyPwdNewPwdEt = (EditText)findViewById(R.id.userModifyPwdNewPwdEt);
        userModifyPwdConfirmPwdEt = (EditText)findViewById(R.id.userModifyPwdConfirmPwdEt);
        userModifyPwdSubmitBtn = (Button)findViewById(R.id.userModifyPwdSubmitBtn);

        userModifyPwdBackBtn.setOnClickListener(this);
        userModifyPwdSubmitBtn.setOnClickListener(this);

        Bundle bundle = getIntent().getExtras();
        modifyPwdType = (ModifyPwdType) bundle.getSerializable(ActivityJumpUtil.Extra.MODIFY_PWD_TYPE);
        userToken = (UserToken) bundle.getSerializable(ActivityJumpUtil.Extra.MODIFY_PWD_TOKEN);
        KLog.e(modifyPwdType);
        KLog.e(userToken);
    }

    @Override
    public UserToken getUserToken() {
        return userToken;
    }

    @Override
    public String getConfirmPwd() {
        return userModifyPwdConfirmPwdEt.getText().toString();
    }

    @Override
    public String getNewPwd() {
        return userModifyPwdNewPwdEt.getText().toString();
    }

    @Override
    public void modifyPwdSucess() {
        toastMsg("密码修改成功");
        this.finish();
    }

    @Override
    public void showProgress() {
        progressDialogShow();
    }

    @Override
    public void hideProgress() {
        progressDialogHiden();
    }

    @Override
    public void toastMsg(String msg) {
        toastMsgShort(msg);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.userModifyPwdBackBtn:
                this.finish();
                break;
            case R.id.userModifyPwdSubmitBtn:
                if(modifyPwdType == ModifyPwdType.FOR_LOGIN_PWD){
                    userModifyPwdPS.submitNewLoginPwd();
                }else if(modifyPwdType == ModifyPwdType.FOR_PAY_PWD){
                    userModifyPwdPS.submitNewPayPwd();
                }
                break;
            default:
                break;
        }
    }
}
